package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.supplier3.SupplierRecommendEntity;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;

public class MapInfoDialog4 extends BaseBottomDialog {

    private SupplierRecommendEntity entity;
    private TextView titleView;
    private TextView tvAuthYear;
    private TextView tvAddress;
    private TextView tvDistance;
    private TextView companyView;
    private RelativeLayout rootLayout;
    private RelativeLayout rlClose;
    private DialogClickCallBack dialogClickCallBack;

    public MapInfoDialog4(Context context, DialogCallBack dialogCallBack) {
        super(context, dialogCallBack);
    }

    public MapInfoDialog4(Context context, int theme, DialogCallBack dialogCallBack) {
        super(context, theme, dialogCallBack);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.map_info_dialog4;
    }

    @Override
    protected void initView(DialogViewHolder holder, Bundle savedInstanceState) {
        titleView = holder.getDialog().findViewById(R.id.title_view);
        tvAuthYear = holder.getDialog().findViewById(R.id.tv_authYear);
        tvAddress = holder.getDialog().findViewById(R.id.tv_address);
        tvDistance = holder.getDialog().findViewById(R.id.tv_distance);
        companyView = holder.getDialog().findViewById(R.id.company_view);
        rlClose = holder.getDialog().findViewById(R.id.rl_close);
        rlClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MapInfoDialog4.this.cancel();
            }
        });
        rootLayout = holder.getDialog().findViewById(R.id.root_layout);
        rootLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogClickCallBack == null) {
                    return;
                }
                if (entity == null) {
                    return;
                }
                dialogClickCallBack.onClickShop(entity.getCompanyId());
                MapInfoDialog4.this.dismiss();
                MapInfoDialog4.this.cancel();
            }
        });
    }

    @Override
    public void setOnDismissListener(@Nullable OnDismissListener listener) {
        super.setOnDismissListener(listener);
        MapInfoDialog4.this.dismiss();
        MapInfoDialog4.this.cancel();
    }

    public SupplierRecommendEntity getData() {
        return entity;
    }

    public MapInfoDialog4 setData(SupplierRecommendEntity entity) {
        this.entity = entity;
        titleView.setText(entity.getName());
        tvAuthYear.setText(entity.getAuthYear());
        tvAddress.setText(entity.getAddress());
        tvDistance.setText(entity.getDistance());
        companyView.setText(entity.getMainBusiness());
        return this;
    }

    public interface DialogClickCallBack {
        void onClickShop(String shopId);
    }

    public MapInfoDialog4 setDialogClickCallBack(DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }
}
